--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--[[

    目前的升级方式为杀死血量至少100的敌人、杀死大boss（未来可能会提供更多经验来源），
    每杀死一只，获得其生命上限1%的经验。
    另外，当boss类敌人死亡时，只要胡桃在其附近(半径25），就会获得其生命上限0.5%的经验。

    inst.components.hutao_com_level_sys:ExpDoDelta(1000)

]]--
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---
    local EXP_BROADCAST_RANGE = 25      --- 经验广播范围
    local EXP_BROADCAST_RANGE_SQ = EXP_BROADCAST_RANGE * EXP_BROADCAST_RANGE -- 经验广播范围平方

    local EXP_PERCENT_FROM_MAX_HEALTH = 0.01 * (TUNING["hutao.Config"].EXP_MULT or 1 )  --- 杀死一只，获得其生命上限1%的经验
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

return function(inst)
    if not TheWorld.ismastersim then
        return
    end
    -------------------------------------------------------------------
    --- 亲自击杀了目标
        inst:ListenForEvent("killed",function(_,_table)
            local target = _table and _table.victim
            if target and target.components.health and target.components.health.maxhealth >= 100 then
                local max_health = target.components.health.maxhealth
                local exp = max_health*EXP_PERCENT_FROM_MAX_HEALTH
                if target:HasTag("epic") then --- boss 只获取 一半，另外一半 来自 范围广播  
                    exp = exp/2
                end
                inst.components.hutao_com_level_sys:ExpDoDelta(exp)
                TheNet:Announce(inst:GetDisplayName().."击杀了["..target:GetDisplayName().."]，获得经验： "..exp)
            end
        end)
    -------------------------------------------------------------------
    --- 范围广播经验
        inst:ListenForEvent("entity_death",function(_,_table)
            local target = _table and _table.inst
            if target and target:HasTag("epic") and target.components.health and target.components.health.maxhealth >= 100 then
                if inst:GetDistanceSqToInst(target) <= EXP_BROADCAST_RANGE_SQ then
                    local max_health = target.components.health.maxhealth
                    local exp = max_health*EXP_PERCENT_FROM_MAX_HEALTH
                    exp = exp/2
                    inst.components.hutao_com_level_sys:ExpDoDelta(exp)
                    TheNet:Announce("BOSS ["..target:GetDisplayName().."]死在"..inst:GetDisplayName().."附近，获得经验： "..exp)
                end
            end
        end,TheWorld)
    -------------------------------------------------------------------
end